package ar.uba.fi.tp2Unit.displayers;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;

import ar.uba.fi.tp2Unit.displayers.xml.TestSuiteXML;
import ar.uba.fi.tp2Unit.displayers.xml.TestSuiteXMLBuilder;
import ar.uba.fi.tp2Unit.displayers.xml.XMLWriter;
import ar.uba.fi.tp2Unit.framework.TestResult;
import ar.uba.fi.tp2Unit.framework.TestResultDisplayable;


/**
 * It writes the results of the execution of a test fixture
 * in a file.
 * 
 * @author grupo12
 * @see {@link TestResultDisplayable}
 */
public class XMLFileTestResultDisplayer implements TestResultDisplayable {

	private String fileName;

	public XMLFileTestResultDisplayer(String fileName) {
		this.fileName = fileName;
	}

	public void display(TestResult testResult) {
		TestSuiteXML rootSuite = TestSuiteXMLBuilder.build(testResult);
		try {
			XMLWriter.write(fileName, rootSuite);
		} catch (ParserConfigurationException e) {
			throw new FileWritingException(e.getMessage());
		} catch (TransformerException e) {
			throw new FileWritingException(e.getMessage());
		}
	}
		
}
